<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据代理</title>
</head>
<body>
    <script>
        let obj1 = {x:100}
        let obj2 = {y:200}

        // obj2 代理 obj1.x 双向绑定
        /* 可以通过修改obj2.x的值 修改obj1.x的值 */
        Object.defineProperty(obj2, 'x', {
            get(){
                return obj1.x
            },
            set(val){
                obj1.x = val
            }
        })

    </script>
</body>
</html>